package com.boo2.controller;

import com.boo2.entity.Address;
import com.boo2.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wzm
 * @create 2024-02-27 11:16
 * project_name:JavaWeb2401
 * @Description
 */
//@RestController  = @Controller + @ResponseBody
@Controller  //控制器 将当前这个类交给框架处理
@ResponseBody
public class ResponseController {

    //1.响应字符串
    @RequestMapping("/hello01")
    public String hello01(){
        return "hello01";
    }



/*
* Controller方法中的return结果怎么就相应给浏览器呢？
* 使用@ResponseBody注解
* 可以加在类上 表示所有方法都返回json格式的数据
* 可以加在方法上表示当前方法返回json数据
* 作用：将返回的集合 对象  字符串转成json响应给前端
* */


//2.响应实体对象
@RequestMapping("/getStu")
public Student getStu(){
    Student student = new Student(1, "zs", 20, null);
    return student;
}

//3.响应集合数据
    @RequestMapping("/getList")
    public List<Student> getList(){
    List<Student> list = new ArrayList<>();
    Address address = new Address();
    address.setId(877);
    address.setCity("昆明");

    list.add(new Student(1, "zs1", 20, address));
    list.add(new Student(2, "zs2", 20, address));
    list.add(new Student(3, "zs3", 20, address));
    return list;

    }




}